<?php
namespace app\components;

use yii\base\Widget;
use backend\modules\content\models\Category;
use yii\helpers\Html;

class Headmenu extends Widget
{
    public $menus;

    public function init()
    {
        parent::init();
        if ($this->menus ==[]) {
            $this->menus = [
                ['catid'=>0,'catname'=>'首页','url'=>'/','target'=>'_blank']
            ];
        }
    }

    public function run()
    {
        $this->menus = Category::find()
            ->where(['status'=>1,'display'=>1,'parentid'=>0])
            ->select('catid,catname,url')
            ->orderBy('listorder DESC,catid DESC')
            ->limit(6)
            ->all();
        return $this->render('menus',['catnames'=>$this->menus]);
//        var_dump($this->menus);exit();
//        return $this->menus;
    }
}